/*     */ package blockbuster.components.motion;
/*     */ import blockbuster.components.BedrockComponentBase;
/*     */ import blockbuster.components.IComponentParticleUpdate;
/*     */ import blockbuster.emitter.BedrockEmitter;
/*     */ import blockbuster.emitter.BedrockParticle;
/*     */ import blockbuster.math.MathUtils;
/*     */ import blockbuster.math.Operation;
/*     */ import blockbuster.math.molang.MolangException;
/*     */ import blockbuster.math.molang.MolangParser;
/*     */ import blockbuster.math.molang.expressions.MolangExpression;
/*     */ import com.google.gson.JsonElement;
/*     */ import com.google.gson.JsonObject;
/*     */ import com.google.gson.JsonPrimitive;
/*     */ import eos.moe.dragoncore.interfaces.IEntity;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Nullable;
/*     */ import javax.vecmath.Tuple3d;
/*     */ import javax.vecmath.Vector3d;
/*     */ import javax.vecmath.Vector3f;
/*     */ import net.minecraft.entity.Entity;
/*     */ import net.minecraft.util.EnumFacing;
/*     */ import net.minecraft.util.math.AxisAlignedBB;
/*     */ import net.minecraft.util.math.BlockPos;
/*     */ 
/*     */ public class BedrockComponentMotionCollision extends BedrockComponentBase implements IComponentParticleUpdate {
/*  28 */   public MolangExpression enabled = MolangParser.ONE;
/*     */   public boolean preserveEnergy = false;
/*     */   public boolean entityCollision;
/*     */   public boolean momentum;
/*  32 */   public float collisionDrag = 0.0F;
/*  33 */   public float bounciness = 1.0F;
/*  34 */   public float randomBounciness = 0.0F;
/*  35 */   public float randomDamp = 0.0F;
/*  36 */   public float damp = 0.0F;
/*     */   public int splitParticleCount;
/*     */   public float splitParticleSpeedThreshold;
/*  39 */   public float radius = 0.01F;
/*     */   public boolean expireOnImpact;
/*  41 */   public MolangExpression expirationDelay = MolangParser.ZERO;
/*     */   
/*     */   public boolean realisticCollision;
/*     */   
/*     */   public boolean realisticCollisionDrag;
/*  46 */   private Vector3d previous = new Vector3d();
/*  47 */   private Vector3d current = new Vector3d();
/*  48 */   private BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
/*     */   
/*     */   public static float getComponent(Vector3f vector, EnumFacing.Axis component) {
/*  51 */     if (component == EnumFacing.Axis.X)
/*  52 */       return vector.x; 
/*  53 */     if (component == EnumFacing.Axis.Y) {
/*  54 */       return vector.y;
/*     */     }
/*     */     
/*  57 */     return vector.z;
/*     */   }
/*     */   
/*     */   public static void setComponent(Vector3f vector, EnumFacing.Axis component, float value) {
/*  61 */     if (component == EnumFacing.Axis.X) {
/*  62 */       vector.x = value;
/*  63 */     } else if (component == EnumFacing.Axis.Y) {
/*  64 */       vector.y = value;
/*     */     } else {
/*  66 */       vector.z = value;
/*     */     } 
/*     */   }
/*     */   
/*     */   public static void negateComponent(Vector3f vector, EnumFacing.Axis component) {
/*  71 */     setComponent(vector, component, -getComponent(vector, component));
/*     */   }
/*     */   
/*     */   public static double getComponent(Vector3d vector, EnumFacing.Axis component) {
/*  75 */     if (component == EnumFacing.Axis.X)
/*  76 */       return vector.x; 
/*  77 */     if (component == EnumFacing.Axis.Y) {
/*  78 */       return vector.y;
/*     */     }
/*     */     
/*  81 */     return vector.z;
/*     */   }
/*     */   
/*     */   public static void setComponent(Vector3d vector, EnumFacing.Axis component, double value) {
/*  85 */     if (component == EnumFacing.Axis.X) {
/*  86 */       vector.x = value;
/*  87 */     } else if (component == EnumFacing.Axis.Y) {
/*  88 */       vector.y = value;
/*     */     } else {
/*  90 */       vector.z = value;
/*     */     } 
/*     */   }
/*     */   
/*     */   public static void negateComponent(Vector3d vector, EnumFacing.Axis component) {
/*  95 */     setComponent(vector, component, -getComponent(vector, component));
/*     */   }
/*     */ 
/*     */   
/*     */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 100 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*     */     
/* 102 */     JsonObject element = elem.getAsJsonObject();
/*     */     
/* 104 */     if (element.has("enabled")) this.enabled = parser.parseJson(element.get("enabled")); 
/* 105 */     if (element.has("entityCollision")) this.entityCollision = element.get("entityCollision").getAsBoolean(); 
/* 106 */     if (element.has("momentum")) this.momentum = element.get("momentum").getAsBoolean(); 
/* 107 */     if (element.has("realistic_collision_drag"))
/* 108 */       this.realisticCollisionDrag = element.get("realistic_collision_drag").getAsBoolean(); 
/* 109 */     if (element.has("collision_drag")) this.collisionDrag = element.get("collision_drag").getAsFloat(); 
/* 110 */     if (element.has("coefficient_of_restitution"))
/* 111 */       this.bounciness = element.get("coefficient_of_restitution").getAsFloat(); 
/* 112 */     if (element.has("bounciness_randomness"))
/* 113 */       this.randomBounciness = element.get("bounciness_randomness").getAsFloat(); 
/* 114 */     if (element.has("preserveEnergy") && element.get("preserveEnergy").isJsonPrimitive()) {
/* 115 */       JsonPrimitive energy = element.get("preserveEnergy").getAsJsonPrimitive();
/*     */       
/* 117 */       if (energy.isBoolean()) {
/* 118 */         this.preserveEnergy = energy.getAsBoolean();
/*     */       } else {
/* 120 */         this.preserveEnergy = MolangExpression.isOne(parser.parseJson((JsonElement)energy));
/*     */       } 
/*     */     } 
/* 123 */     if (element.has("damp")) this.damp = element.get("damp").getAsFloat(); 
/* 124 */     if (element.has("random_damp")) this.randomDamp = element.get("random_damp").getAsFloat(); 
/* 125 */     if (element.has("split_particle_count"))
/* 126 */       this.splitParticleCount = element.get("split_particle_count").getAsInt(); 
/* 127 */     if (element.has("split_particle_speedThreshold"))
/* 128 */       this.splitParticleSpeedThreshold = element.get("split_particle_speedThreshold").getAsFloat(); 
/* 129 */     if (element.has("collision_radius")) this.radius = element.get("collision_radius").getAsFloat(); 
/* 130 */     if (element.has("expire_on_contact")) this.expireOnImpact = element.get("expire_on_contact").getAsBoolean(); 
/* 131 */     if (element.has("expirationDelay")) this.expirationDelay = parser.parseJson(element.get("expirationDelay")); 
/* 132 */     if (element.has("realisticCollision")) {
/* 133 */       this.realisticCollision = element.get("realisticCollision").getAsBoolean();
/*     */     }
/* 135 */     return super.fromJson((JsonElement)element, parser);
/*     */   }
/*     */ 
/*     */   
/*     */   public JsonElement toJson() {
/* 140 */     JsonObject object = new JsonObject();
/*     */     
/* 142 */     if (!MolangExpression.isOne(this.enabled)) object.add("enabled", this.enabled.toJson()); 
/* 143 */     if (this.realisticCollision) object.addProperty("realisticCollision", Boolean.valueOf(true)); 
/* 144 */     if (this.entityCollision) object.addProperty("entityCollision", Boolean.valueOf(true)); 
/* 145 */     if (this.momentum) object.addProperty("momentum", Boolean.valueOf(true)); 
/* 146 */     if (this.realisticCollisionDrag) object.addProperty("realistic_collision_drag", Boolean.valueOf(true)); 
/* 147 */     if (this.collisionDrag != 0.0F) object.addProperty("collision_drag", Float.valueOf(this.collisionDrag)); 
/* 148 */     if (this.bounciness != 1.0F) object.addProperty("coefficient_of_restitution", Float.valueOf(this.bounciness)); 
/* 149 */     if (this.randomBounciness != 0.0F) object.addProperty("bounciness_randomness", Float.valueOf(this.randomBounciness)); 
/* 150 */     if (this.preserveEnergy) object.addProperty("preserveEnergy", Boolean.valueOf(this.preserveEnergy)); 
/* 151 */     if (this.damp != 0.0F) object.addProperty("damp", Float.valueOf(this.damp)); 
/* 152 */     if (this.randomDamp != 0.0F) object.addProperty("random_damp", Float.valueOf(this.randomDamp)); 
/* 153 */     if (this.splitParticleCount != 0) object.addProperty("split_particle_count", Integer.valueOf(this.splitParticleCount)); 
/* 154 */     if (this.splitParticleSpeedThreshold != 0.0F)
/* 155 */       object.addProperty("split_particle_speedThreshold", Float.valueOf(this.splitParticleSpeedThreshold)); 
/* 156 */     if (this.radius != 0.01F) object.addProperty("collision_radius", Float.valueOf(this.radius)); 
/* 157 */     if (this.expireOnImpact) object.addProperty("expire_on_contact", Boolean.valueOf(true)); 
/* 158 */     if (!MolangExpression.isZero(this.expirationDelay)) {
/* 159 */       object.add("expirationDelay", this.expirationDelay.toJson());
/*     */     }
/* 161 */     return (JsonElement)object;
/*     */   }
/*     */ 
/*     */   
/*     */   public void update(BedrockEmitter emitter, BedrockParticle particle) {
/* 166 */     particle.realisticCollisionDrag = this.realisticCollisionDrag;
/*     */     
/* 168 */     if (emitter.world == null) {
/*     */       return;
/*     */     }
/*     */     
/* 172 */     float r = this.radius;
/*     */     
/* 174 */     this.previous.set((Tuple3d)particle.getGlobalPosition(emitter, particle.prevPosition));
/* 175 */     this.current.set((Tuple3d)particle.getGlobalPosition(emitter));
/*     */     
/* 177 */     Vector3d prev = this.previous;
/* 178 */     Vector3d now = this.current;
/*     */     
/* 180 */     double x = now.x - prev.x;
/* 181 */     double y = now.y - prev.y;
/* 182 */     double z = now.z - prev.z;
/* 183 */     boolean veryBig = (Math.abs(x) > 10.0D || Math.abs(y) > 10.0D || Math.abs(z) > 10.0D);
/*     */     
/* 185 */     this.pos.func_189532_c(now.x, now.y, now.z);
/*     */     
/* 187 */     if (veryBig || !emitter.world.func_175667_e((BlockPos)this.pos)) {
/*     */       return;
/*     */     }
/*     */     
/* 191 */     AxisAlignedBB aabb = new AxisAlignedBB(prev.x - r, prev.y - r, prev.z - r, prev.x + r, prev.y + r, prev.z + r);
/*     */     
/* 193 */     double d0 = y;
/* 194 */     double origX = x;
/* 195 */     double origZ = z;
/*     */     
/* 197 */     List<Entity> entities = emitter.world.func_72872_a(Entity.class, aabb.func_72321_a(x, y, z));
/* 198 */     HashMap<Entity, AxisAlignedBB> entityAABBs = new HashMap<>();
/* 199 */     HashMap<Entity, CollisionOffset> staticEntityAABBs = new HashMap<>();
/*     */     
/* 201 */     List<AxisAlignedBB> list = emitter.world.func_184144_a(null, aabb.func_72321_a(x, y, z));
/*     */     
/* 203 */     if ((!list.isEmpty() || (!entities.isEmpty() && this.entityCollision)) && !particle.intersected) {
/* 204 */       particle.firstIntersection = particle.age;
/* 205 */       particle.intersected = true;
/*     */     } 
/*     */     
/* 208 */     if (!particle.manual && !Operation.equals(this.enabled.get(), 0.0D)) {
/* 209 */       if (this.entityCollision) {
/* 210 */         for (Entity entity : entities) {
/* 211 */           AxisAlignedBB aabb2 = new AxisAlignedBB(prev.x - r, prev.y - r, prev.z - r, prev.x + r, prev.y + r, prev.z + r);
/* 212 */           AxisAlignedBB entityAABB = entity.func_174813_aQ();
/*     */           
/* 214 */           double y2 = y, x2 = x, z2 = z;
/*     */           
/* 216 */           y2 = entityAABB.func_72323_b(aabb2, y2);
/* 217 */           aabb2 = aabb2.func_72317_d(0.0D, y2, 0.0D);
/*     */           
/* 219 */           x2 = entityAABB.func_72316_a(aabb2, x2);
/* 220 */           aabb2 = aabb2.func_72317_d(x2, 0.0D, 0.0D);
/*     */           
/* 222 */           z2 = entityAABB.func_72322_c(aabb2, z2);
/* 223 */           aabb2 = aabb2.func_72317_d(0.0D, 0.0D, z2);
/*     */           
/* 225 */           if (d0 == y2 && origX == x2 && origZ == z2) {
/* 226 */             entityAABBs.put(entity, entityAABB); continue;
/*     */           } 
/* 228 */           list.add(entityAABB);
/* 229 */           staticEntityAABBs.put(entity, new CollisionOffset(entityAABB, x2, y2, z2));
/*     */           
/* 231 */           if (this.momentum && d0 == y2) {
/* 232 */             momentum(particle, entity);
/*     */           }
/*     */         } 
/*     */       }
/*     */ 
/*     */       
/* 238 */       CollisionOffset offsetData = calculateOffsets(aabb, list, x, y, z);
/* 239 */       aabb = offsetData.aabb;
/* 240 */       x = offsetData.x;
/* 241 */       y = offsetData.y;
/* 242 */       z = offsetData.z;
/*     */       
/* 244 */       if (d0 != y || origX != x || origZ != z) {
/* 245 */         collision(particle, emitter, prev);
/*     */         
/* 247 */         now.set(aabb.field_72340_a + r, aabb.field_72338_b + r, aabb.field_72339_c + r);
/*     */         
/* 249 */         if (d0 != y) {
/* 250 */           if (d0 < y) { now.y = aabb.field_72338_b; }
/* 251 */           else { now.y = aabb.field_72337_e; }
/*     */           
/* 253 */           now.y += (d0 < y) ? r : -r;
/*     */           
/* 255 */           collisionHandler(particle, emitter, EnumFacing.Axis.Y, now, prev);
/*     */ 
/*     */ 
/*     */           
/* 259 */           particle.entityCollisionTime.keySet().retainAll(staticEntityAABBs.keySet());
/*     */           
/* 261 */           for (Map.Entry<Entity, CollisionOffset> entry : staticEntityAABBs.entrySet()) {
/* 262 */             CollisionOffset offsetData2 = entry.getValue();
/* 263 */             AxisAlignedBB entityAABB = offsetData2.aabb;
/* 264 */             Entity collidingEntity = entry.getKey();
/*     */             
/* 266 */             if (d0 != offsetData2.y && origX == offsetData2.x && origZ == offsetData2.z) {
/* 267 */               inertia(particle, collidingEntity, now);
/*     */             }
/*     */             
/* 270 */             if (particle.entityCollisionTime.containsKey(collidingEntity)) {
/* 271 */               ((Vector3f)particle.entityCollisionTime.get(collidingEntity)).y = particle.age; continue;
/*     */             } 
/* 273 */             particle.entityCollisionTime.put(entry.getKey(), new Vector3f(-1.0F, particle.age, -1.0F));
/*     */           } 
/*     */         } 
/*     */ 
/*     */         
/* 278 */         if (origX != x) {
/* 279 */           if (origX < x) { now.x = aabb.field_72340_a; }
/* 280 */           else { now.x = aabb.field_72336_d; }
/*     */           
/* 282 */           now.x += (origX < x) ? r : -r;
/*     */           
/* 284 */           collisionHandler(particle, emitter, EnumFacing.Axis.X, now, prev);
/*     */         } 
/*     */         
/* 287 */         if (origZ != z) {
/* 288 */           if (origZ < z) { now.z = aabb.field_72339_c; }
/* 289 */           else { now.z = aabb.field_72334_f; }
/*     */           
/* 291 */           now.z += (origZ < z) ? r : -r;
/*     */           
/* 293 */           collisionHandler(particle, emitter, EnumFacing.Axis.Z, now, prev);
/*     */         } 
/*     */         
/* 296 */         particle.position.set((Tuple3d)now);
/*     */         
/* 298 */         drag(particle);
/* 299 */       } else if (entityAABBs.isEmpty() && this.realisticCollisionDrag) {
/*     */         
/* 301 */         particle.dragFactor = 0.0F;
/*     */       } 
/*     */ 
/*     */       
/* 305 */       for (Map.Entry<Entity, AxisAlignedBB> entry : entityAABBs.entrySet()) {
/* 306 */         AxisAlignedBB entityAABB = entry.getValue();
/* 307 */         Entity entity = entry.getKey();
/*     */         
/* 309 */         Vector3f speedEntity = new Vector3f((float)(entity.field_70165_t - entity.field_70169_q), (float)(entity.field_70163_u - entity.field_70167_r), (float)(entity.field_70161_v - entity.field_70166_s));
/*     */ 
/*     */         
/* 312 */         if (speedEntity.x != 0.0F || speedEntity.y != 0.0F || speedEntity.z != 0.0F) {
/* 313 */           Vector3f ray = speedEntity;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */           
/* 327 */           Vector3d frac = intersect(ray, particle.getGlobalPosition(emitter), entityAABB);
/*     */           
/* 329 */           if (frac != null) {
/* 330 */             particle.position.add((Tuple3d)frac);
/*     */             
/* 332 */             AxisAlignedBB aabb2 = new AxisAlignedBB(particle.position.x - r, particle.position.y - r, particle.position.z - r, particle.position.x + r, particle.position.y + r, particle.position.z + r);
/*     */             
/* 334 */             collision(particle, emitter, prev);
/*     */             
/* 336 */             if ((aabb2.field_72340_a < entityAABB.field_72336_d && aabb2.field_72336_d > entityAABB.field_72336_d) || (aabb2.field_72336_d > entityAABB.field_72340_a && aabb2.field_72340_a < entityAABB.field_72340_a)) {
/* 337 */               entityCollision(particle, emitter, entity, EnumFacing.Axis.X, prev);
/*     */             }
/*     */             
/* 340 */             if ((aabb2.field_72338_b < entityAABB.field_72337_e && aabb2.field_72337_e > entityAABB.field_72337_e) || (aabb2.field_72337_e > entityAABB.field_72338_b && aabb2.field_72338_b < entityAABB.field_72338_b)) {
/* 341 */               entityCollision(particle, emitter, entity, EnumFacing.Axis.Y, prev);
/*     */             }
/*     */             
/* 344 */             if ((aabb2.field_72339_c < entityAABB.field_72334_f && aabb2.field_72334_f > entityAABB.field_72334_f) || (aabb2.field_72334_f > entityAABB.field_72339_c && aabb2.field_72339_c < entityAABB.field_72339_c)) {
/* 345 */               entityCollision(particle, emitter, entity, EnumFacing.Axis.Z, prev);
/*     */             }
/*     */           } 
/*     */         } 
/*     */       } 
/* 350 */       if (!entityAABBs.isEmpty()) {
/* 351 */         drag(particle);
/*     */       }
/*     */     } 
/*     */   }
/*     */   
/*     */   public void collision(BedrockParticle particle, BedrockEmitter emitter, Vector3d prev) {
/* 357 */     if (this.expireOnImpact) {
/* 358 */       double expirationDelay = this.expirationDelay.get();
/*     */       
/* 360 */       if (expirationDelay != 0.0D && !particle.collided) {
/* 361 */         particle.setExpirationDelay(expirationDelay);
/* 362 */       } else if (expirationDelay == 0.0D && !particle.collided) {
/* 363 */         particle.dead = true;
/*     */         
/*     */         return;
/*     */       } 
/*     */     } 
/*     */     
/* 369 */     if (particle.relativePosition) {
/* 370 */       particle.relativePosition = false;
/* 371 */       particle.prevPosition.set((Tuple3d)prev);
/*     */     } 
/*     */     
/* 374 */     particle.collided = true;
/*     */   }
/*     */   
/*     */   public void entityCollision(BedrockParticle particle, BedrockEmitter emitter, Entity entity, EnumFacing.Axis component, Vector3d prev) {
/* 378 */     Vector3f entitySpeed = new Vector3f((float)(entity.field_70165_t - entity.field_70169_q), (float)(entity.field_70163_u - entity.field_70167_r), (float)(entity.field_70161_v - entity.field_70166_s));
/* 379 */     Vector3d entityPosition = new Vector3d(entity.field_70165_t, entity.field_70163_u, entity.field_70161_v);
/*     */     
/* 381 */     if (this.momentum) {
/* 382 */       momentum(particle, entity);
/*     */     }
/*     */ 
/*     */     
/* 386 */     float tmpTime = getComponent(particle.collisionTime, component);
/* 387 */     double delta = getComponent(particle.position, component) - getComponent(entityPosition, component);
/*     */     
/* 389 */     setComponent(particle.position, component, getComponent(particle.position, component) + ((delta > 0.0D) ? this.radius : -this.radius));
/*     */     
/* 391 */     collisionHandler(particle, emitter, component, particle.position, prev);
/*     */ 
/*     */     
/* 394 */     setComponent(particle.collisionTime, component, tmpTime);
/*     */     
/* 396 */     if (delta > 0.0D && component == EnumFacing.Axis.Y)
/*     */     {
/* 398 */       inertia(particle, entity, null);
/*     */     }
/*     */ 
/*     */     
/* 402 */     if (getComponent(particle.speed, component) > 0.0F)
/* 403 */     { if (getComponent(entitySpeed, component) < 0.0F) negateComponent(particle.speed, component);  }
/* 404 */     else if (getComponent(particle.speed, component) < 0.0F && 
/* 405 */       getComponent(entitySpeed, component) > 0.0F) { negateComponent(particle.speed, component); }
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 410 */     setComponent(particle.position, component, getComponent(particle.position, component) + (getComponent(particle.speed, component) / 20.0F));
/*     */   }
/*     */   
/*     */   public void collisionHandler(BedrockParticle particle, BedrockEmitter emitter, EnumFacing.Axis component, Vector3d now, Vector3d prev) {
/* 414 */     float collisionTime = getComponent(particle.collisionTime, component);
/* 415 */     float speed = getComponent(particle.speed, component);
/* 416 */     float accelerationFactor = getComponent(particle.accelerationFactor, component);
/*     */ 
/*     */     
/* 419 */     if (this.realisticCollision) {
/* 420 */       if (collisionTime != (particle.age - 1)) {
/* 421 */         if (this.bounciness != 0.0F) {
/* 422 */           setComponent(particle.speed, component, -speed * this.bounciness);
/*     */         }
/* 424 */       } else if (collisionTime == (particle.age - 1)) {
/* 425 */         setComponent(particle.speed, component, 0.0F);
/*     */       } 
/*     */     } else {
/* 428 */       setComponent(particle.accelerationFactor, component, accelerationFactor * -this.bounciness);
/*     */     } 
/*     */     
/* 431 */     if (collisionTime != (particle.age - 1)) {
/*     */       
/* 433 */       if (this.randomBounciness != 0.0F) {
/* 434 */         particle.speed = randomBounciness(particle.speed, component, this.randomBounciness);
/*     */       }
/*     */ 
/*     */       
/* 438 */       if (this.splitParticleCount != 0) {
/* 439 */         splitParticle(particle, emitter, component, now, prev);
/*     */       }
/*     */ 
/*     */       
/* 443 */       if (this.damp != 0.0F) {
/* 444 */         particle.speed = damping(particle.speed);
/*     */       }
/*     */     } 
/*     */     
/* 448 */     if (collisionTime != (particle.age - 1)) {
/* 449 */       particle.bounces++;
/*     */     }
/*     */     
/* 452 */     setComponent(particle.collisionTime, component, particle.age);
/*     */   }
/*     */   
/*     */   public void inertia(BedrockParticle particle, Entity entity, @Nullable Vector3d now) {
/* 456 */     if (this.collisionDrag == 0.0F) {
/*     */       return;
/*     */     }
/*     */     
/* 460 */     Vector3d entitySpeed = new Vector3d(entity.field_70165_t - entity.field_70169_q, entity.field_70163_u - entity.field_70167_r, entity.field_70161_v - entity.field_70166_s);
/*     */ 
/*     */     
/* 463 */     double prevPrevPosX = ((IEntity)entity).getPrevPrevPosX();
/* 464 */     double prevPrevPosY = ((IEntity)entity).getPrevPrevPosY();
/* 465 */     double prevPrevPosZ = ((IEntity)entity).getPrevPrevPosZ();
/*     */     
/* 467 */     Vector3d prevEntitySpeed = new Vector3d(entity.field_70169_q - prevPrevPosX, entity.field_70167_r - prevPrevPosY, entity.field_70166_s - prevPrevPosZ);
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 475 */     if (!particle.entityCollisionTime.containsKey(entity)) {
/* 476 */       prevEntitySpeed.scale(0.0D);
/*     */     } else {
/*     */       
/* 479 */       particle.offset.x = entitySpeed.x;
/* 480 */       particle.offset.z = entitySpeed.z;
/*     */       
/* 482 */       if (now == null) {
/* 483 */         particle.position.x += entitySpeed.x;
/* 484 */         particle.position.z += entitySpeed.z;
/*     */       } else {
/* 486 */         now.x += entitySpeed.x;
/* 487 */         now.z += entitySpeed.z;
/*     */       } 
/*     */     } 
/*     */     
/* 491 */     particle.speed.x = (float)(particle.speed.x + Math.round((prevEntitySpeed.x - entitySpeed.x) * 1000.0D) / 250.0D);
/* 492 */     particle.speed.y = (float)(particle.speed.y + Math.round((prevEntitySpeed.y - entitySpeed.y) * 1000.0D) / 250.0D);
/* 493 */     particle.speed.z = (float)(particle.speed.z + Math.round((prevEntitySpeed.z - entitySpeed.z) * 1000.0D) / 250.0D);
/*     */   }
/*     */   
/*     */   public void momentum(BedrockParticle particle, Entity entity) {
/* 497 */     particle.speed.x = (float)(particle.speed.x + 2.0D * (entity.field_70165_t - entity.field_70169_q));
/* 498 */     particle.speed.y = (float)(particle.speed.y + 2.0D * (entity.field_70163_u - entity.field_70167_r));
/* 499 */     particle.speed.z = (float)(particle.speed.z + 2.0D * (entity.field_70161_v - entity.field_70166_s));
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void drag(BedrockParticle particle) {
/* 505 */     if ((this.randomBounciness == 0.0F && !this.realisticCollision) || Math.round(particle.speed.x * 10000.0F) != 0 || Math.round(particle.speed.y * 10000.0F) != 0 || Math.round(particle.speed.z * 10000.0F) != 0) {
/* 506 */       if (this.realisticCollisionDrag) {
/* 507 */         particle.dragFactor = 3.0F * this.collisionDrag;
/*     */       } else {
/* 509 */         particle.dragFactor += this.collisionDrag;
/*     */       } 
/*     */     }
/*     */   }
/*     */   
/*     */   public Vector3f damping(Vector3f vector) {
/* 515 */     float random = (float)(this.randomDamp * (Math.random() * 2.0D - 1.0D));
/* 516 */     float clampedValue = MathUtils.clamp(1.0F - this.damp + random, 0.0F, 1.0F);
/*     */     
/* 518 */     vector.scale(clampedValue);
/*     */     
/* 520 */     return vector;
/*     */   }
/*     */   
/*     */   public void splitParticle(BedrockParticle particle, BedrockEmitter emitter, EnumFacing.Axis component, Vector3d now, Vector3d prev) {
/* 524 */     float speed = getComponent(particle.speed, component);
/*     */     
/* 526 */     if (Math.abs(speed) <= Math.abs(this.splitParticleSpeedThreshold)) {
/*     */       return;
/*     */     }
/*     */     
/* 530 */     for (int i = 0; i < this.splitParticleCount; i++) {
/* 531 */       BedrockParticle splitParticle = emitter.createParticle(false);
/*     */       
/* 533 */       particle.softCopy(splitParticle);
/*     */       
/* 535 */       splitParticle.position.set((Tuple3d)now);
/* 536 */       splitParticle.prevPosition.set((Tuple3d)prev);
/*     */ 
/*     */       
/* 539 */       splitParticle.bounces = 1;
/*     */       
/* 541 */       double splitPosition = getComponent(splitParticle.position, component);
/*     */       
/* 543 */       setComponent(splitParticle.collisionTime, component, particle.age);
/* 544 */       setComponent(splitParticle.position, component, splitPosition);
/*     */       
/* 546 */       Vector3f randomSpeed = randomBounciness(particle.speed, component, (this.randomBounciness != 0.0F) ? this.randomBounciness : 10.0F);
/*     */       
/* 548 */       randomSpeed.scale(1.0F / this.splitParticleCount);
/* 549 */       splitParticle.speed.set((Tuple3f)randomSpeed);
/*     */       
/* 551 */       if (this.damp != 0.0F) {
/* 552 */         splitParticle.speed = damping(splitParticle.speed);
/*     */       }
/*     */       
/* 555 */       emitter.splitParticles.add(splitParticle);
/*     */     } 
/*     */     
/* 558 */     particle.dead = true;
/*     */   }
/*     */   
/*     */   public Vector3f randomBounciness(Vector3f vector0, EnumFacing.Axis component, float randomness) {
/* 562 */     if (randomness != 0.0F) {
/*     */       
/* 564 */       Vector3f vector = new Vector3f(vector0);
/*     */       
/* 566 */       float randomfactor = 0.25F;
/* 567 */       float prevLength = vector.length();
/* 568 */       randomness *= 0.1F;
/* 569 */       float random1 = (float)Math.random() * randomness;
/* 570 */       float random2 = (float)((randomness * randomfactor) * (Math.random() * 2.0D - 1.0D));
/* 571 */       float random3 = (float)((randomness * randomfactor) * (Math.random() * 2.0D - 1.0D));
/*     */       
/* 573 */       float vectorValue = getComponent(vector, component);
/*     */       
/* 575 */       if (component == EnumFacing.Axis.X) {
/* 576 */         vector.y += random2;
/* 577 */         vector.z += random3;
/* 578 */       } else if (component == EnumFacing.Axis.Y) {
/* 579 */         vector.x += random2;
/* 580 */         vector.z += random3;
/*     */       } else {
/* 582 */         vector.y += random2;
/* 583 */         vector.x += random3;
/*     */       } 
/*     */       
/* 586 */       if (this.bounciness != 0.0F) {
/* 587 */         setComponent(vector, component, vectorValue + ((vectorValue < 0.0F) ? -random1 : random1));
/* 588 */         vector.scale(prevLength / vector.length());
/* 589 */       } else if (vector.x != 0.0F || vector.y != 0.0F || vector.z != 0.0F) {
/*     */ 
/*     */ 
/*     */ 
/*     */         
/* 594 */         if (this.preserveEnergy) {
/* 595 */           setComponent(vector, component, 0.0F);
/*     */         }
/*     */ 
/*     */         
/* 599 */         if (vector.x != 0.0F || vector.y != 0.0F || vector.z != 0.0F) {
/* 600 */           vector.scale(prevLength / vector.length());
/*     */         }
/*     */         
/* 603 */         setComponent(vector, component, vectorValue);
/*     */       }
/*     */       else {
/*     */         
/* 607 */         return vector0;
/*     */       } 
/*     */       
/* 610 */       return vector;
/*     */     } 
/*     */     
/* 613 */     return vector0;
/*     */   }
/*     */   
/*     */   public Vector3d intersect(Vector3f ray, Vector3d orig, AxisAlignedBB aabb) {
/* 617 */     double tmin = (aabb.field_72340_a - orig.x) / ray.x;
/* 618 */     double tmax = (aabb.field_72336_d - orig.x) / ray.x;
/*     */     
/* 620 */     if (tmin > tmax) {
/* 621 */       double tminTmp = tmin;
/* 622 */       tmin = tmax;
/* 623 */       tmax = tminTmp;
/*     */     } 
/*     */     
/* 626 */     double tymin = (aabb.field_72338_b - orig.y) / ray.y;
/* 627 */     double tymax = (aabb.field_72337_e - orig.y) / ray.y;
/*     */     
/* 629 */     if (tymin > tymax) {
/* 630 */       double tyminTmp = tymin;
/* 631 */       tymin = tymax;
/* 632 */       tymax = tyminTmp;
/*     */     } 
/*     */     
/* 635 */     if (tmin > tymax || tymin > tmax) {
/* 636 */       return null;
/*     */     }
/* 638 */     if (tymin > tmin) {
/* 639 */       tmin = tymin;
/*     */     }
/* 641 */     if (tymax < tmax) {
/* 642 */       tmax = tymax;
/*     */     }
/* 644 */     double tzmin = (aabb.field_72339_c - orig.z) / ray.z;
/* 645 */     double tzmax = (aabb.field_72334_f - orig.z) / ray.z;
/*     */     
/* 647 */     if (tzmin > tzmax) {
/* 648 */       double tzminTmp = tzmin;
/* 649 */       tzmin = tzmax;
/* 650 */       tzmax = tzminTmp;
/*     */     } 
/*     */     
/* 653 */     if (tmin > tzmax || tzmin > tmax) {
/* 654 */       return null;
/*     */     }
/* 656 */     if (tzmax < tmax) {
/* 657 */       tmax = tzmax;
/*     */     }
/* 659 */     Vector3d ray1 = new Vector3d(ray);
/*     */     
/* 661 */     ray1.scale(tmax);
/*     */     
/* 663 */     return ray1;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public CollisionOffset calculateOffsets(AxisAlignedBB aabb, List<AxisAlignedBB> list, double x, double y, double z) {
/* 675 */     for (AxisAlignedBB axisalignedbb : list) {
/* 676 */       y = axisalignedbb.func_72323_b(aabb, y);
/*     */     }
/*     */     
/* 679 */     aabb = aabb.func_72317_d(0.0D, y, 0.0D);
/*     */     
/* 681 */     for (AxisAlignedBB axisalignedbb1 : list) {
/* 682 */       x = axisalignedbb1.func_72316_a(aabb, x);
/*     */     }
/*     */     
/* 685 */     aabb = aabb.func_72317_d(x, 0.0D, 0.0D);
/*     */     
/* 687 */     for (AxisAlignedBB axisalignedbb2 : list) {
/* 688 */       z = axisalignedbb2.func_72322_c(aabb, z);
/*     */     }
/*     */     
/* 691 */     aabb = aabb.func_72317_d(0.0D, 0.0D, z);
/*     */     
/* 693 */     return new CollisionOffset(aabb, x, y, z);
/*     */   }
/*     */ 
/*     */   
/*     */   public int getSortingIndex() {
/* 698 */     return 50;
/*     */   }
/*     */   
/*     */   public class CollisionOffset {
/*     */     public AxisAlignedBB aabb;
/*     */     public double x;
/*     */     public double y;
/*     */     public double z;
/*     */     
/*     */     public CollisionOffset(AxisAlignedBB aabb, double x, double y, double z) {
/* 708 */       this.aabb = aabb;
/* 709 */       this.x = x;
/* 710 */       this.y = y;
/* 711 */       this.z = z;
/*     */     }
/*     */   }
/*     */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\motion\BedrockComponentMotionCollision.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */